/**
 * 
 */
package de.iplon.DataViewer;

/**
 * @author Klaus Versl, Georg Wieland
 * 
 * description:
 * collects a data stream
 * from an abstract source and
 * processes it to a series of x/y  values (timestamp/value)
 */
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;

import org.achartengine.model.TimeSeries;
//import org.achartengine.model.XYMultipleSeriesDataset;
//import org.achartengine.renderer.XYMultipleSeriesRenderer;
//import org.achartengine.renderer.XYSeriesRenderer;
//import org.achartengine.ChartFactory;
//import org.achartengine.GraphicalView;
//import org.achartengine.chart.PointStyle;
//import org.achartengine.*;

abstract class Serie extends Thread{
	protected String 			mSource;
	protected String			mSerieName;
	protected java.util.Date 	mTs[];
	protected double 			mValue[];
	protected TimeSeries 		mSeries;
	protected String 			mRawdata;
	protected boolean 			mReady = false;
	protected boolean			mError = false;
	protected int 				mTzoneOffset = 19800000; // default: Indian Standard Time
		
	abstract public void run();
	
	abstract protected boolean parseRawdata();
	
	protected boolean createTimeSeries(){
		mSeries = new TimeSeries(mSerieName);			
		for(int i=0;i<mTs.length;i++)
	    {
			mSeries.add(mTs[i], mValue[i]);
	    }
		return true;
	}
	
	java.util.Date getDate(){
		int i = 0;
		do{
			if (mTs[i] != null) return mTs[i];
			i++;
		} while (i<mTs.length);
		return null;
	}
	
	void shiftTimeZone(){
		// add mTzoneOffset to  mTs[]
		for (int i=0;i<mTs.length;i++){
			if (!mTs[i].equals(null)) mTs[i] = new java.util.Date(mTs[i].getTime()+mTzoneOffset);
		}
	}
	
	TimeSeries getSerie(){
		return mSeries;
	}
	
	boolean isReady() {
		// thread sync: wait for run()
		  return mReady;
	}

	void setReady(boolean ready) {
		// thread sync: wait for run()
		this.mReady = ready;
	}
	
	boolean getError(){
		return this.mError;
	}
}
